package com.jiutong.meipengdai.ui.activitys;

import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiutong.meipengdai.R;
import com.jiutong.meipengdai.base.BaseActivity;
import com.jiutong.meipengdai.entity.ArticleRespond;
import com.jiutong.meipengdai.http.model.interfaces.ArticleBiz;
import com.jiutong.meipengdai.http.model.requests.ArticleRequest;
import com.jiutong.meipengdai.http.present.ArticalPresent;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作用:
 * Created by 78 on 2017/6/19.
 */
public class AgreementActivity extends BaseActivity implements ArticleBiz {

    @Bind(R.id.tv_title)
    TextView tv_title;
    @Bind(R.id.rl_back)
    RelativeLayout rl_back;
    @Bind(R.id.wv_agreement)
    WebView wv_agreement;
    private ArticalPresent articalPresent;
    private ArticleRequest request;

    @Override
    public int getLayoutResouceId() {
        return R.layout.activity_agreement;
    }

    @Override
    protected void initView() {
        super.initView();
        ButterKnife.bind(this);
        tv_title.setText("服务协议");

        articalPresent = new ArticalPresent(this, this);
        articalPresent.getArticle();
    }

    @OnClick({R.id.rl_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
        }
    }

    @Override
    public String getArticleId() {
        return "add27473e743437db670185922fa8840";
    }

    @Override
    public void onSuccess(Object object) {
        ArticleRespond respond = (ArticleRespond) object;
        if (respond.getResCode().equals("200")) {

//            html = respond.getData().getArticleData().getContent();

            //能够的调用JavaScript代码
            wv_agreement.getSettings().setJavaScriptEnabled(true);
            //加载HTML字符串进行显示

        // plan_html.loadData(planweb,"text/html", "utf-8");//在我这里这个显示是乱码，所以用下面这种
            wv_agreement.loadDataWithBaseURL(null,respond.getData().getArticleData().getContent(),"text/html", "utf-8",null);
            wv_agreement.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);

//            wv_agreement.SET(respond.getData().getArticleData().getContent());
        }else{
            toastShortShow(respond.getResDesc());
        }
    }

    @Override
    public void onError(Throwable e) {

    }
}
